/**
 * @file   QMiraP3ArmPainter.h
 * @author Josep Sabater (jsabaterm@el.ub.edu)
 * @date   November, 2016
 * @version 1.0.0
 * @ingroup QMira
 * @brief  Interface for a P3 Arm painter
 *
 * Contains the methods each P3Arm Painter must implement.
 */
#ifndef Q_MIRA_P3ARM_PAINTER_H
#define Q_MIRA_P3ARM_PAINTER_H

#include "QMiraIRobot2DPainter.h"
#include "MiraIRobot2D.h"

#include <MiraTypes.h>
#include <MiraPlacement2D.h>

#include <QPainterPath>

namespace QMira{
    class QP3ArmPainter : public QIRobot2DPainter {
    public:
        QP3ArmPainter(const IRobot2D &robot);
        QP3ArmPainter(const IRobot2D &robot, const MiraUtilUBLib::DoubleMatrix_t &qs);
        ~QP3ArmPainter() override;
        
        void draw(QPainter &painter, const QIRobot2DPainter::FrameId_t frame) const override;
        QIRobot2DPainter::FrameId_t addFrame(const MiraUtilUBLib::DoubleCont_t &q) override;
        unsigned int clearFrames() override;
            
    private:
        const IRobot2D &robot_; //!< Low level details of the robot to draw
        const MiraUtilUBLib::DoubleCont_t &linksLen_; 
        Joint2D::Joint2DMatrix_t framesCont_; //!< Frames to draw
        
        QPainterPath  j1Path_; //!< J1 path
        QPainterPath  l3Path_; //!< l3 path
        
        void init_();
        
        void drawJoint_(const Joint2D &joint, 
                        QPainter &painter, 
                        const QColor &color) const;
        void drawJointPath_(const Joint2D &joint,
                            QPainter &painter, 
                            const QColor &color,
                            const QPainterPath &path) const;
        
        void drawLongTubePath_( const Joint2D &joint, 
                                QPainter &painter,
                                const QColor &color, 
                                const QPainterPath &path) const;    
        void drawLink_(const Joint2D &jointA,
                       const Joint2D &jointB,
                       QPainter &painter, 
                       const QColor &color) const;
        void drawLink_(const Joint2D &jointA,
                       const Joint2D &jointB,
                       const unsigned int length,
                       QPainter &painter, 
                       const QColor &color) const;        
    };
}
#endif /*Q_MIRA_P3ARM_PAINTER_H*/